package com.lou.springboot.controller.admin;

import com.lou.springboot.common.ResultVO;
import com.lou.springboot.common.ResultVOUtil;
import com.lou.springboot.entity.Track;
import com.lou.springboot.enums.ResultEnum;
import com.lou.springboot.service.TrackService;
import com.lou.springboot.utils.IpUtils;
import com.lou.springboot.utils.JsonUtils;
import com.lou.springboot.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class TrackController {

    @Autowired
    private TrackService trackService;

    @GetMapping("/tracks")
    public String list(HttpServletRequest request) {
        request.setAttribute("path", "tracks");
        return "admin/track";
    }

    @GetMapping("/tracks/list")
    @ResponseBody
    public ResultVO list(@RequestParam Map<String, Object> map) {
        if (StringUtils.isEmpty(map.get("page")) || StringUtils.isEmpty(map.get("limit"))) {
            return ResultVOUtil.error(ResultEnum.PARAM_ERROR);
        }
        PageUtil pageUtil = new PageUtil(map);
        return ResultVOUtil.success(trackService.getTrackList(pageUtil));
    }
}
